UserPostsList.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Link from 'next/link';
  2. import { Eye, Heart, MessageCircle } from 'lucide-react';
  3. import { formatDate } from '@/lib/utils/format';
  4. import { UserPostRow, UserProfileDto } from '@/types/account/profile';
  5. type Props = {
  6. list: UserPostRow[];
  7. author?: UserProfileDto|null;
  8. };
  9. export default function UserPostsList({ list, author }: Props) {
  10. if (list.length === 0) {
  11. return <p className="user-profile__empty">작성한 게시글이 없습니다.</p>;
  12. }
  13. const authorDisplay = author?.name || author?.memberSID || null;
  14. const avatarInitial = (authorDisplay?.charAt(0) || '?').toUpperCase();
  15. return (
  16. <ul className="user-profile__list">
  17. {list.map((row) => (
  18. <li key={row.postID} className="user-profile__list-item">
  19. <Link href={`/post/${row.postID}`} className="user-profile__list-link">
  20. <div className="user-profile__list-body">
  21. {author && (
  22. <header className="user-profile__list-author">
  23. {author.thumb ? (
  24. <img src={author.thumb} alt={authorDisplay ?? ''} className="user-profile__list-author-avatar" />
  25. ) : (
  26. <span className="user-profile__list-author-avatar user-profile__list-author-avatar--fallback">{avatarInitial}</span>
  27. )}
  28. <span className="user-profile__list-author-name">{authorDisplay}</span>
  29. <span className="user-profile__list-author-handle">@{author.memberSID}</span>
  30. <span className="user-profile__list-time">· {formatDate(row.createdAt)}</span>
  31. </header>
  32. )}
  33. <div className="user-profile__list-meta">
  34. <span className="user-profile__list-board">{row.boardName}</span>
  35. </div>
  36. <p className="user-profile__list-subject">{row.subject}</p>
  37. {row.thumbnail && (
  38. <img src={row.thumbnail} alt="" className="user-profile__list-thumb" loading="lazy" />
  39. )}
  40. <div className="user-profile__list-stats">
  41. <span className="user-profile__list-stat" title="조회 수">
  42. <Eye size={14} strokeWidth={1.75} />
  43. {row.views.toLocaleString()}
  44. </span>
  45. <span className="user-profile__list-stat" title="좋아요">
  46. <Heart size={14} strokeWidth={1.75} />
  47. {row.likes.toLocaleString()}
  48. </span>
  49. <span className="user-profile__list-stat" title="댓글">
  50. <MessageCircle size={14} strokeWidth={1.75} />
  51. {row.comments.toLocaleString()}
  52. </span>
  53. </div>
  54. </div>
  55. </Link>
  56. </li>
  57. ))}
  58. </ul>
  59. );
  60. }